package com.ehome.emergency.utils;

import java.util.List;

/**
 * BasicFramework
 *
 * @author: xiaolei
 * @date: 2016-01-26 21:49
 * @desc: 分页工具类
 */
public class Pager {
    private List<?> list;       //结果集
    private int totalRecords;   //查询记录数
    private int rows;           //每页多少条记录
    private int page;           //第几页

    private String orderby;         // 升序Or降序
    private String orderbyProperty; //排序字段名称

    public enum Orderby {
        DESC,   // 降序
        ASC     // 升序
    }

    /**
     * 总页数
     */
    public int getTotalPages() {
        return (totalRecords + rows - 1) / rows;

    }

    /**
     * 取得首页
     */
    public int getTopPageNo() {
        return 1;
    }

    /**
     * 上一页
     */
    public int getPreviousPageNo() {
        if (page <= 1) {
            return 1;
        }
        return page - 1;
    }

    /**
     * 下一页
     */
    public int getNextPageNo() {
        if (page >= getBottomPageNo()) {
            return getBottomPageNo();
        }
        return page + 1;
    }

    /**
     * 取得尾页
     */
    public int getBottomPageNo() {
        return getTotalPages();
    }

    public List<?> getList() {
        return list;
    }

    public void setList(List<?> list) {
        this.list = list;
    }

    public int getTotalRecords() {
        return totalRecords;
    }

    public void setTotalRecords(int totalRecords) {
        this.totalRecords = totalRecords;
    }

    public int getRows() {
        return rows;
    }

    public void setRows(int rows) {
        this.rows = rows;
    }

    public int getPage() {
        return page;
    }

    public void setPage(int page) {
        this.page = page;
    }

    public String getOrderby() {
        return orderby;
    }

    public void setOrderby(String orderby) {
        this.orderby = orderby;
    }

    public String getOrderbyProperty() {
        return orderbyProperty;
    }

    public void setOrderbyProperty(String orderbyProperty) {
        this.orderbyProperty = orderbyProperty;
    }
}
